import Vue from 'vue'
import Vuex from 'vuex'
import { TOGGLE_VISIBLE } from './action-types'
import { SET_SHOW_MAP } from './mutation-types'
import Storage from 'vue-ls'

Vue.use(Storage, {
  namespace: 'vuejs__', // key prefix
  name: 'ls', // name variable Vue.[ls] or this.[$ls],
  storage: 'local', // storage name session, local, memory
})
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    showMap: Vue.ls.get('showMap')
  },

  mutations: {
    [SET_SHOW_MAP](state, payload) {
      state.showMap = payload
      Vue.ls.set('showMap', payload)
    }
  },

  actions: {
    [TOGGLE_VISIBLE]({ commit }, payload) {
      setTimeout(() => {
        commit(SET_SHOW_MAP, payload)
      }, 0)
    }
  }
})


